﻿using Game.NetWork;
using GameEntitySystem;

namespace Game
{
    public class ComponentCoffer2Package : IPackage
    {
        public enum EventType
        {
            SyncStat,
            TurnToLowSen,
            TurnToHighSen,
            ZeroSen
        }

        public float Sen;

        public float rate;

        public float dt1;

        public float ATKNow;

        public string password1 = "12345";

        public EventType m_eventType;

        public ushort entityId;

        public byte ID => 110;

        public Client To { get; set; }

        public Client Except { get; set; }

        public Client From { get; set; }

        public ClientState MinNeedState => ClientState.ProjectLoaded;

        public ComponentCoffer2Package()
        {
        }

        public ComponentCoffer2Package(ComponentCoffer flu, EventType eventType)
        {
            entityId = flu.Entity.EntityId;
            m_eventType = eventType;
            password1 = flu.password;
        }

        public void WriteData(PackageStreamWriter writer)
        {
            writer.Write(entityId);
            writer.WriteEnum(m_eventType);
            writer.Write(password1);
        }

        public void ReadData(PackageStreamReader reader)
        {
            entityId = reader.ReadUInt16();
            m_eventType = reader.ReadEnum<EventType>();
            password1 = reader.ReadString();
        }

        public void Handle(ProjectNet projectNet, NetNode netNode, bool isServer)
        {
            if (m_eventType != 0)
            {
                return;
            }

            projectNet.FindEntityById(entityId, delegate (Entity entity)
            {
                ComponentCoffer componentCoffer = entity.FindComponent<ComponentCoffer>();
                if (componentCoffer != null)
                {
                    componentCoffer.password = password1;
                }
            });
        }
    }
}